﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class UIHeroLuckTemplete :MonoBehaviour
    {
        //未激活
        public GameObject luckNameTextInAc;
        public GameObject luckDescribeTextInAc;

        //激活的
        public GameObject luckNameTextAct;
        public GameObject luckDescribeTextAct;

        public GameObject active;//激活
        public GameObject inactive;//未激活

        public UISprite inAcSpr;
        public UISprite acSpr;

        public bool isActive;

        public void Init(string luckId,bool actived=false)
        {
            var luck = Dict.DictDataManager.Instance.tableYuanDao.GetById(luckId);
            Init(TableTextBlo.GetText(luck.yuanName), CommonMethod.GetLuckDesTex(luckId, actived), actived,luck.type<=4);
        }

        private void Init(string luckName,string describe="test",bool active=false,bool hero=true)
        {

            //描述文字
            if (hero)
            {
                luckDescribeTextInAc.GetComponent<UILabel>().text = "[3c3c3c]" + describe.Substring(luckName.Length + "[3c3c3c]".Length + 1);
                luckDescribeTextAct.GetComponent<UILabel>().text = "[313131]" + describe.Substring(luckName.Length + "[313131]".Length + 4);
            }
            else
            {
                luckDescribeTextInAc.GetComponent<UILabel>().text = "[3c3c3c]" + describe.Substring(luckName.Length + "[3c3c3c]".Length + 1);
                luckDescribeTextAct.GetComponent<UILabel>().text = "[313131]" + describe.Substring(luckName.Length + "[313131]".Length + 4+5);
            }
            //luckName = TableTextBlo.GetText(luckName);

            luckNameTextAct.GetComponent<UILabel>().text = "[3c3c3c]" + luckName+"[-]";
            luckNameTextInAc.GetComponent<UILabel>().text = "[313131]" + luckName+"[-]";

            this.name = luckName;
            
            SetActiveModule( active );
        }

        public int Height
        {
            get
            {
                if(isActive)
                {
                    return luckDescribeTextAct.GetComponent<UILabel>().height+20;
                }
                else
                {
                    return luckDescribeTextInAc.GetComponent<UILabel>().height+20;
                }
            }
        }

        protected void SetActiveModule(bool active)
        {
            this.isActive = active;
            this.active.SetActive( active );
            this.inactive.SetActive( !active );
        }
    }
}